/**
 * 
 */
package com.shine.icis.dao.imp;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.sql.hibernate.CommQuery;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.icis.dao.IBusinessConfDAO;
import com.shine.icis.dao.imp.BaseHibernateDAO;
import com.shine.icis.hbean.BusinessConf;

/**
 * @author zsy
 *
 */
public class BusinessConfDAO extends BaseHibernateDAO implements IBusinessConfDAO {
	
	@Override
	public BusinessConf findById(int id) {
		BusinessConf sl = (BusinessConf)getSession().get(BusinessConf.class, id);
		return sl;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public ListPage<BusinessConf> findBusinessConfPage(QueryParameters qp) {
		if (qp == null) {
			throw new IllegalArgumentException("非法参数:查询参数对象为null");
		}
		try {
			StringBuffer sbQueryString = new StringBuffer();			
			sbQueryString.append("select bf from BusinessConf as bf where 1=1");
			if(qp.getParameter("busiName") != null){
				sbQueryString.append(" and bf.busiName like :busiName");
				qp.toArountParameter("busiName");
			}
			
			if(qp.getParameter("enableFlag") != null){
				sbQueryString.append(" and bf.enableFlag = :enableFlag");
			}
			
			return new CommQuery<BusinessConf>().queryListPage(qp, 
					qp.appendOrders(sbQueryString, "bf" ), getSession());
		} catch(RuntimeException re) {
			re.printStackTrace();
			return new  ListPage<BusinessConf>();
		}
	}
}
